export default {
	data() {
		return {
			model: {},
			buildData: [],
			rules:[],
		}
	},
	methods: {
		_initData(buildData,propModel) {
			let _model = {};
			let _rules = [];
			if(Object.keys(propModel).length !== 0){
				for (let i = 0, len = buildData.length; i < len; i++) {
					if(buildData[i].type === 'switch'){
						_model[buildData[i].vmodel] = propModel[buildData[i].prop] || false;
					}else if(buildData[i].type === 'checkbox'){
						_model[buildData[i].vmodel] = [];
						buildData[i].checkboxList.map((value,index)=>{
							if(propModel[buildData[i].prop].indexOf(value.name) != -1){
								_model[buildData[i].vmodel].push(value.name)
								return value.checked = true;
							}
						})
					}else{
						_model[buildData[i].vmodel] = propModel[buildData[i].prop] || '';
					}
					if(buildData[i].rule){
						_rules[buildData[i].prop] = buildData[i].rule;
					}
				}
			}else{
				for (let i = 0, len = buildData.length; i < len; i++) {
					if(buildData[i].type === 'switch'){
						_model[buildData[i].vmodel] = false;
					}else{
						_model[buildData[i].vmodel] = '';
					}
					if(buildData[i].rule){
						_rules[buildData[i].prop] = buildData[i].rule;
					}
				}
			}
			this.buildData = buildData;
			this.model = _model;
			this.rules = _rules;
		},
		selectDefaultValue(index, value) {
			let selet = this.buildData[index].selectList;
			for (let i = 0; i < selet.length; i++) {
				if (selet[i].value === value) {
					return [i];
					break;
				}
			}
			return [0];
		},
		selectDefaultRegion(index, value){
			if(value){
				return value.split('-');
			}else{
				return [];
			}
		},
		selectClick(e,item){
			if(item.selectType === 'action-sheet'){
				this.model[item.prop] = item.selectList[e].text;
			}else if(item.selectType === 'region-picker'){
				this.model[item.prop] = `${e.province.label}-${e.city.label}-${e.area.label}`;
			}else if(item.selectType === 'single-column'){
				this.model[item.prop] = e[0].value;
			}else if(item.type === 'checkbox' || item.type === 'radio'){
				this.model[item.prop] = e;
			}
		},
		rightSlotClick(e,item){
			
		}
	}
}
